package leetcode_0424

func characterReplacement1(s string, k int) int {

	result, maxCount, left, right, ch := 0, 0, 0, 0, [26]int{}

	for right < len(s) {
		ch[s[right]-'A']++
		maxCount = max(maxCount, ch[s[right]-'A'])
		right++

		if right-left > maxCount+k {
			ch[s[left]-'A']--
			left++
		}

		result = max(result, right-left)
	}

	return result
}

func max(a int, b int) int {
	if a > b {
		return a
	}
	return b
}
